using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace trainstorm.BaseClass
{
	public class Button
	{
		private Vector2 position;
		private SpriteFont font;
		private Texture2D image;
		private bool available;
		private bool pressed;
		private string text;

		public Button(Vector2 position, Texture2D image, bool state, SpriteFont font, string caption)
		{
			this.position = position;
			this.image = image;
			this.available = state;
			this.pressed = false;
			this.text = caption;
			this.font = font;
		}
		public bool isPressed()
		{
			return pressed;
		}
		public bool isAvailable()
		{
			return available;
		}
		public void setPressed(float x, float y)
		{
			pressed = new Rectangle((int)position.X, (int)position.Y, image.Width, image.Height).Contains((int)x, (int)y);
		}
		public void draw(SpriteBatch batch)
		{
			Color color;
			if (!available)
				color = Color.DarkGray;
			else if (pressed)
				color = Color.CornflowerBlue;
			else
				color = Color.White;

			batch.Draw(image, position, color);
			batch.DrawString(font, text, new Vector2(position.X, position.Y - 10), color);	//belum selesai, posisi status bar
		}
		public void update(GameTime gameTime)
		{
			setPressed(TouchPanel.GetState().ElementAt(0).Position.X, TouchPanel.GetState().ElementAt(0).Position.Y);
		}
	}
}
